package com.huiyujiaoyu.powertime.ui.my;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.huiyujiaoyu.base.BaseActivity;
import com.huiyujiaoyu.base.BaseFragment;
import com.huiyujiaoyu.powertime.R;
import com.huiyujiaoyu.powertime.model.TabEntity;
import com.huiyujiaoyu.powertime.ui.adapter.AllFragmentPagerAdapter;
import com.huiyujiaoyu.util.ActivityUtil;
import com.huiyujiaoyu.util.Constant;
import com.huiyujiaoyu.util.DisplayUtil;
import com.huiyujiaoyu.widget.LlkjToolBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static android.R.attr.data;
import static android.R.attr.id;

/**
 * Created by win7 on 2017/6/18.
 * 我的收藏
 */

public class MyYHQActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    LlkjToolBar mToolbar;
    @BindView(R.id.tab)
    CommonTabLayout mTab;
    @BindView(R.id.view_pager_2)
    ViewPager mViewPager2;
    private List<BaseFragment> mBaseFragments;
    private AllFragmentPagerAdapter adapter;
    private String[] titles;
    private int whattype;
    public static void launch(Context context) {
        ActivityUtil.startActivity(context, MyYHQActivity.class);
    }


    @Override
    protected void initView() {
        super.initView();
        whattype = getIntent().getIntExtra(Constant.DATA,0);
        setToolbar(mToolbar);
        mToolbar.setToolBar("我的优惠券", true, "", R.mipmap.icon_titlebar_back, false, "", LlkjToolBar.isNull);
        mBaseFragments = new ArrayList<>();
        mBaseFragments.add(BaseListFragment.newInstance(2,1));
        mBaseFragments.add(BaseListFragment.newInstance(2,2));
        mBaseFragments.add(BaseListFragment.newInstance(2,3));
        titles = new String[3];
        titles[0] = "未使用";
        titles[1] = "已使用";
        titles[2] = "已过期";
        adapter = new AllFragmentPagerAdapter(getSupportFragmentManager(),mBaseFragments);
        mViewPager2.setAdapter(adapter);
        ArrayList<CustomTabEntity> dts = new ArrayList<>();
        dts.add(new TabEntity(titles[0]));
        dts.add(new TabEntity(titles[1]));
        dts.add(new TabEntity(titles[2]));
        mTab.setTabData(dts);
        mTab.setCurrentTab(0);
        mTab.getLayoutParams().height = DisplayUtil.dip2px(mContext,45);
    }

    @Override
    protected void initListener() {
        super.initListener();
        mTab.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mViewPager2.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        mViewPager2.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                mTab.setCurrentTab(position);
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_tablaytviewpager;
    }

    public void setResult(String yhqid,String money){
        if(whattype==1){
            Intent data = new Intent();
            data.putExtra(Constant.DATA,yhqid);
            data.putExtra(Constant.DATA2,money);
            setResult(RESULT_OK,data);
            finish();
        }
    }

}
